package main

import "fmt"

func main() {
	v := longestCommonPrefix([]string{"cir","car"})
	fmt.Println(v)
}

// TODO
func longestCommonPrefix(strs []string) string {
	r := []byte{}
	f := strs[0]
	l := len(strs) - 1

	for i := 0; i < len(f); i++ {
		c := 0
		for _, v := range strs[1:] {
			if i > len(v)-1 {
				goto l
			}

			if v[i] == f[i] {
				c++
			} else {
				goto l
			}
		}

		if l == c {
			r = append(r, f[i])
		}
	}
l:
	return string(r)
}
